package org.apache.rocketmq.example.file;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

// MappedFile 可以直接使用，本质上就是 Java 的 MappedByteBuffer 封装
public class Mmap {
    public static void main(String[] args) throws IOException {
        RandomAccessFile raf = new RandomAccessFile(new File("d:/work/data/0"), "rw");
        FileChannel fc = raf.getChannel();
        // 只是建立了映射关系
        MappedByteBuffer buffer = fc.map(FileChannel.MapMode.READ_WRITE, 0, 20);

        buffer.put("Hello RocketMQ".getBytes());


        buffer.force();
    }
}
